<%
System.out.println("======== Report by module =========");
//--------------------------------------------------------------------------------->
//
// Copyright 2002 e Professional Corporation.  All Rights Reserved.
//
// File:       	CFHDRP03.jsp
//
// Author:   	Udong
//
// Start Date:	05/01/48
//
// Finish Date: XX/XX/XXXX 
//
// Update Date : 02/02/2005 by Udong
// ............Add export to excel..........
// Update Date : 03/02/2005 by Udong
// ............Add wording "Please note ...", Add check Level..........
//--------------------------------------------------------------------------------->
%>
<HTML>
<HEAD>
<STYLE>
.titleNormal{
	font-family: Cordia ;
	font-size:11px;
	font-weight:normal;
}
</STYLE>
<%@ page 
		language			="java"
		contentType	="text/html; charset=CP874"
		pageEncoding="CP874"
		import				="com.epro.standard.frontend.util.FileInfoUtil,
										java.util.Vector,
										com.softplus.carrefour.hd.bltier.admin.ICFHDSystemViewer,
										com.softplus.carrefour.hd.bltier.admin.CFHDSystemManage,
										com.softplus.carrefour.hd.CFHDSystem,
										com.softplus.carrefour.hd.bltier.admin.ICFHDModuleViewer,
										com.softplus.carrefour.hd.bltier.admin.CFHDModuleManage,
										com.softplus.carrefour.hd.bltier.admin.ICountryViewer,
										com.softplus.carrefour.hd.bltier.admin.CountryManage,
										com.softplus.carrefour.hd.bltier.entity.Country,
										java.text.SimpleDateFormat,
										com.softplus.carrefour.hd.bltier.util.DateUtil,
										com.softplus.carrefour.hd.bltier.entity.UserAccount,
										com.softplus.carrefour.hd.bltier.admin.IUserLevelViewer,
										com.softplus.carrefour.hd.bltier.admin.UserLevelManage,
										com.softplus.carrefour.hd.bltier.entity.UserLevel"
%>
<%@	taglib uri="../WEB-INF/HeadTag.tld" prefix="head"%>
<%@ taglib uri="../WEB-INF/TextfieldTag.tld" prefix="textfield"%>
<head:Head
		author			="Udong"
		styleFile		="../theme/defaultTheme.css"
		jsFile			="../script/spTitleRefresh.js,../script/dateCalendar.js,../script/checkValidData.js,../script/convertDataType.js,../script/Alert.js"></head:Head>

</HEAD>
<%@ include file="../include/eproFileInfo.jsp" %>
<%@ include file="../include/spUserVOInclude.jsp" %>
<%
		String selectWidth		= "155";
		SimpleDateFormat	simpDF	=	new SimpleDateFormat("dd/MM/yyyy");
		UserAccount					userSession		=  (UserAccount) request.getSession().getAttribute("userVO");//"kunlaporn_c";
		String								userID					= userSession.getUserId();//"admin";//userVO.getUserId();//request.getParameter("uid");

		FileInfoUtil			fileInfoUtil 		= (FileInfoUtil) session.getAttribute("fileInfoUtil");
        fileInfoUtil.setMenuIDCode("CFHDRPMT03");
        fileInfoUtil.setMenuName(" Total Time Consumption for Problem Solving by Case");
        fileInfoUtil.setMasterWording(" Total Time Consumption for Problem Solving by Case");
        fileInfoUtil.setMenuDesc(" Total Time Consumption for Problem Solving by Case");
// === define object ===
		ICFHDSystemViewer		systemManage	=	(CFHDSystemManage)CFHDSystem.getControlClass("SYSTEM");
		ICFHDModuleViewer		moduleManage=	(CFHDModuleManage)CFHDSystem.getControlClass("MODULE");
		ICountryViewer					countryManage	=	(CountryManage)CFHDSystem.getControlClass("COUNTRY");
		IUserLevelViewer			levelManage		=	(UserLevelManage)CFHDSystem.getControlClass("USER_LEVEL");
// === define vector ===
		Vector	systemVector	=	new Vector(0);
		Vector	moduleVector	=	new Vector(0);
		Vector	countryVector	=	new Vector(0);
// ........check user level..........
		String	level	=	levelManage.getUserLevelByUserID(userID)==null? "":levelManage.getUserLevelByUserID(userID);

        if(level.equals("")){
            out.println("<script src=\"../script/Alert.js\" type=\"text/javascript\"></script>");
            out.println("<script type=\"text/javascript\">");
            out.println("if(showOInfoDialog(\"Authentication Failed!\", \"You might not be authorized in E-Helpdesk System. Please Contact Administrator.\\n click OK  to continue.\", \"OK\" )){");

            out.println("  parent.location =parent.location; ");
            out.println(" } \n </script>");                     
        }
%>
<BODY>
<%=fileInfoUtil.MasterHeadTable() %>
<script src="../script/spToolbar.js" type="text/javascript"></script>
	<a href="../../CFRL/CFRLWEBMN01.jsp">
		<img alt="Back to view all cases" src="../images/icon/toolbar/nBackToMenu.gif" width="21" height="21" border="0" onmouseout="imgOut(this)" onmouseover="imgOver(this)" /></a>
<FORM name="frm" action="CFHDRPRP03.jsp">
<TABLE align="center" border="0" bordercolor="purple">
	<TR>
		<TD class="titleFont">Open Case Country : </TD>
		<%	
		if (	level.equals(UserLevel.ADMIN) || 
				level.equals(UserLevel.LEVEL_2_AMS_ZONE_ASIA) || 
				level.equals(UserLevel.LEVEL_3_AMS_BANGKOK) || 
				level.equals(UserLevel.PRODUCTION_STAFF)				)
		{%>
		<TD><SELECT name="country" style="width: <%=selectWidth%>">
							<OPTION value="ALL">All</OPTION>
		<%
				countryVector	=	countryManage.getAllCountry();
				if (countryVector != null)
				{		for (int m=0;m<countryVector.size();m++)
						{		Country	countryEntity	=	(Country)countryVector.elementAt(m);
		%>
							<OPTION value="<%=countryEntity.getCountryId()%>"><%=countryEntity.getCountryName()%></OPTION>
		<%			}%>
		<% }%>
					</SELECT>
		</TD>
		<%
		}else{ //end if not user in country%>
		<TD><SELECT name="country" style="width: 220px" >
						<OPTION value="<%=userSession.getCountry().getCountryId()%>"><%=userSession.getCountry().getCountryName()%></OPTION>
					</SELECT></TD>
		<%}%>
	</TR>
	<TR>
		<TD class="titleFont">Case Type : </TD>
		<TD class="titleNormal"><INPUT type="checkbox" value="P1" name="caseP1"> User Question(P1)</TD>
	</TR>
	<TR>
		<TD></TD>
		<TD class="titleNormal"><INPUT type="checkbox" value="P2" name="caseP2"> Problem Report(P2)</TD>
	</TR>
	<TR>
		<TD></TD>
		<TD class="titleNormal"><INPUT type="checkbox" value="P3" name="caseP3"> Change Request(P3)</TD>
	</TR>
	<INPUT type="hidden" value="" name="caseP4">
<!-- 
	<TR>
		<TD></TD>
		<TD class="titleNormal"><INPUT type="checkbox" value="P4" name="caseP4"> Service Request(P4)</TD>
	</TR>
 -->
	<TR>
		<TD class="titleFont">Open Case Date </TD>
	</TR>
	<TR>
		<TD class="titleFont">From : </TD>
		<TD><textfield:textfield value="<%=simpDF.format(DateUtil.getLocalDate(userID))%>" name="fromDate" readonly="yes" dataType="date" label1="From Date" label2="To Date" isBetween="yes" firstValue="yes"
														compareWith="toDate" condition="<="></textfield:textfield>
					<IMG src="../images/icon/calendar/nCalendar.gif" onmouseover="this.src='../images/icon/calendar/oCalendar.gif'"
								onmouseout="this.src='../images/icon/calendar/nCalendar.gif'" alt="Calendar" style='cursor: hand' onclick="CalendarFromDate()"> </TD>
		<TD class="titleFont">To : </TD>
		<TD><textfield:textfield value="<%=simpDF.format(DateUtil.getLocalDate(userID))%>" name="toDate" readonly="yes" dataType="date" label1="From Date" label2="To Date" isBetween="yes" firstValue="no"
														compareWith="fromDate" condition="<=" ></textfield:textfield>
					<IMG src="../images/icon/calendar/nCalendar.gif" onmouseover="this.src='../images/icon/calendar/oCalendar.gif'"
								onmouseout="this.src='../images/icon/calendar/nCalendar.gif'" alt="Calendar" style='cursor: hand' onclick="CalendarToDate()"> </TD>
	</TR>
	<TR><TD colspan="4" align="center" height="50" valign="bottom">
						<INPUT type="button" value="View Report" onclick="submitForm()">
						<INPUT type="button" value="Export To Excel" onclick="submitFormExcel()"></TD></TR>
	<TR><TD colspan="4">
			<TABLE width="510" align="center" border="0"><TR>
					<TD align="right" width="50%"  valign="top"><FONT color="red" style="font: bold;">*</FONT></TD>
					<TD><FONT color="red" style="font: bold;">Please Note: To display report in the correct format, please select 'Open' button to view report before save it as an excel file</FONT></TD>
			</TR></TABLE>
	</TD></TR>
</TABLE>
</FORM>
<SCRIPT>
/*	function limitModule()
	{
			var sysNow	=	frm.system.value;
			var whole			=	new Array(<%//=wholeModule%>);
			var	len				=	frm.module.length;

			// remove all from SELECT
			for (var k=len;k<=(len)&&(k>=0);k--)
			{
					frm.module.remove(k);
			}// end for remove data
					
			if (sysNow=="")
			{
					var module0	=	document.createElement("OPTION");
					module0.text	=	"All";
					frm.module.add(module0);
			}else{
					// add data to SELECT
					for (var m=0;m<whole.length;m++)
					{
							if (whole[m].search(sysNow) != -1)
							{
									var	myRegExp	=	" - ";
									var	temp				=	whole[m].substring(0,whole[m].search(myRegExp));
									eval('var module'+m+'	=	document.createElement("OPTION")');
									eval('module'+m+'.text	=	temp');
									eval('module'+m+'.value=	temp');
									eval('frm.module.add(module'+m+')');
							}
					}// end for add data
			} // end if system not null
*/
	// search()
			/*var myRegExp = "xx";									
			var myStr	=  "udong na rak and xxx";
			alert(myStr.search(myRegExp));*/

	// add OPTION to SELECT
			/*var module0 = document.createElement("OPTION");
			module0.text="";
			module0.value="";
			frm.module.add(module0);*/
	//}

	function CalendarFromDate()
	{
		document.all.fromDate.focus();
		document.all.fromDate.value = window.showModalDialog('Calendar.jsp','window ','status:no;dialogHeight:231px;dialogWidth:262px;scroll:no');	
		if(document.all.fromDate.value == "undefined")
		{	showOWarningDialog("warning","<B>Please Input Open Case Date From again","OK");
			document.all.fromDate.value='';}
        else {document.all.fromDate.focus();}//
	}
	function CalendarToDate()
	{
		//document.all.toDate.value=window.showModalDialog('../AD/Calendar.jsp','window ','status:no;dialogHeight:231px;dialogWidth:262px;scroll:no');
		document.all.toDate.value = window.showModalDialog('Calendar.jsp','window ','status:no;dialogHeight:231px;dialogWidth:262px;scroll:no');	
		if(document.all.toDate.value == "undefined")   
		{		document.all.toDate.value = "";
				showOWarningDialog("warning","<B>Please Input Open Case Date To again","OK");
				document.all.toDate.focus();				
		}
		else {document.all.toDate.focus();}
	}

	function submitForm()
	{
			if( 	isNull(frm.toDate,"Open Case Date")&&
					isNull(frm.fromDate,"Open Case Date")	)
			{
					if(	!(frm.caseP1.checked)&&
							!(frm.caseP2.checked)&&
							!(frm.caseP3.checked)&&	
							!(frm.caseP4.checked))
					{		showOWarningDialog("warning","<T>Please enter : <B>Case Type<B>.","OK");		}
					else
					{		frm.submit()		}
			}
	}

	function submitFormExcel()
	{
			var sendP1="";
			var sendP2="";
			var sendP3="";
			var sendP4="";
			if (frm.caseP1.checked)
			{		sendP1	=	frm.caseP1.value;	}
			if (frm.caseP2.checked)
			{		sendP2	=	frm.caseP2.value;	}
			if (frm.caseP3.checked)
			{		sendP3	=	frm.caseP3.value;	}
			if (frm.caseP4.checked)
			{		sendP4	=	frm.caseP4.value;	}

			if( 	isNull(frm.toDate,"Open Case Date")&&
					isNull(frm.fromDate,"Open Case Date")	)
			{
					if(	!(frm.caseP1.checked)&&
							!(frm.caseP2.checked)&&
							!(frm.caseP3.checked)&&
							!(frm.caseP4.checked)	)
					{		showOWarningDialog("warning","<T>Please enter : <B>Case Type<B>.","OK");		}
					else
					{		var url = "CFHDRPRP03_excel.jsp?country="+frm.country.value+"&caseP1="+sendP1+"&caseP2="+sendP2+
																							"&caseP3="+sendP3+"&caseP4="+sendP4+"&fromDate="+frm.fromDate.value+"&toDate="+frm.toDate.value;
							window.open(url);
					}
			}
	}

/*function checkLevel()
	{
		var checkLevel	= "<%//=level%>";
		if(checkLevel=="")
		{
			if(showOInfoDialog("Authentication Failed!", "You might not authorized in Report System. Please Contact Administrator.\n click OK  to continue.", "OK" ))
			{	   <%//=backClick%> ;	}
		}
	}
*/
</SCRIPT>
</BODY>
</HTML>